package ${package.Controller};

import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};

<#if restControllerStyle>
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.pagehelper.PageInfo;


import java.util.List;
/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Api("${table.comment!}")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    public ${table.serviceName} ${table.entityPath}Service;


    /**
     * 查询列表
     * @param entity ${entity}
     * @return ResponseEntity
     */
    @ApiOperation("${table.comment!}列表")
    @GetMapping("/list")
    public ResponseEntity list(${entity} entity) {
        List<${entity}> list = ${table.entityPath}Service.list(entity);
        return ResponseEntity.ok(list);
    }

    /**
     * 查询分页
     * @param entity ${entity}
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return ResponseEntity
     */
    @ApiOperation("${table.comment!}分页")
    @GetMapping("/pg")
    public ResponseEntity pg(${entity} entity, int pageNum, int pageSize) {
        PageInfo pg = ${table.entityPath}Service.pg(entity, pageNum, pageSize);
        return ResponseEntity.ok(pg);
    }

     /**
     * 添加
     * @param entity ${entity}
     * @return ResponseEntity
     */
    @ApiOperation("${table.comment!}添加")
    @PostMapping("/add")
    public ResponseEntity add(@RequestBody ${entity} entity) {
        ${table.entityPath}Service.save(entity);
        return new ResponseEntity(HttpStatus.OK);
    }

     /**
     * 修改
     * @param entity ${entity}
     * @return ResponseEntity
     */
    @ApiOperation("${table.comment!}修改")
    @PostMapping("/update")
    public ResponseEntity update(@RequestBody ${entity} entity) {
        ${table.entityPath}Service.updateById(entity);
        return new ResponseEntity(HttpStatus.OK);
    }

    /**
     * 删除
     * @param id int
     * @return ResponseEntity
     */
    @ApiOperation("${table.comment!}删除")
    @PostMapping("/delete")
    public ResponseEntity delete(int id) {
        ${table.entityPath}Service.removeById(id);
        return new ResponseEntity(HttpStatus.OK);
    }

}
</#if>
